package com.biostime.qdingding.modules.qd.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.qdingding.common.persistence.Page;
import com.biostime.qdingding.common.service.CrudService;
import com.biostime.qdingding.modules.qd.api.dto.ActivityDetailDto;
import com.biostime.qdingding.modules.qd.dao.ActivityDao;
import com.biostime.qdingding.modules.qd.entity.Activity;
import com.biostime.qdingding.modules.qd.entity.Activitymember;
import com.biostime.qdingding.modules.sys.entity.User;

/**
 * ActivityService
 * @author chenweicheng
 * @version 2015-12-06
 */
@Service
@Transactional(readOnly = true)
public class ActivityService extends CrudService<ActivityDao, Activity> {
	
	@Override
		public Page<Activity> findPage(Page<Activity> page, Activity entity) {
			if(entity == null){
				entity = new Activity();
			}
			dataScopeFilter(entity, "dsf", "id=a.center_id", "id=a.create_by");
			
			return super.findPage(page, entity);
		}
	
//	 <!-- ————————————————————————————楚河汉界，谁敢动我的，打死! ————————————————————————————————————-->	
	public ActivityDetailDto apiGetActivity(String id,String userId) {
		return dao.apiGetActivity(id,userId);
	}
	
	public List<ActivityDetailDto> apiFindList(String userId,String centerId){
		return dao.apiFindList(userId, centerId);
	}
	
	public int apiInsertActivity(String activityId,String type,String userId){
		Activitymember activityMember = new Activitymember();
		activityMember.setActivityId(Integer.parseInt(activityId)); 
		activityMember.setMemberId(Integer.parseInt(userId)); 
		activityMember.setCreateBy(new User("0")); 
		activityMember.setUpdateBy(new User("0"));
		activityMember.setUpdateDate(new Date());
		activityMember.setCreateDate(new Date()); 
		activityMember.setDelFlag("0"); 
		activityMember.setType(type);
		if(type.equals("collect")){
			activityMember.setState("collected"); 			
		}
		else if(type.equals("enroll")){
			activityMember.setState("pending"); 
		}
		return dao.apiInsertActivity(activityMember);
	}
	
	public List<ActivityDetailDto> apiMyFindList(String userId,String type){
		return dao.apiMyFindList(userId, type);
	}
	
	public int apiDeleteOrder(String activityId,String userId,String type){
		return dao.apiDeleteOrder(activityId,userId,type);
	}
	
	public Activitymember apiFindOrderById(String activityId,String userId,String type){
		return dao.apiFindOrderById(activityId,userId,type);
	}	
	
	public List<String> apiGetImgs(String activityId){
		return dao.apiGetImgs(activityId);
	}
	
	public int apiGetNumber(String activityId){
		return dao.apiGetNumber(activityId);
	}	
	
	public List<HashMap<String,Object>> activityScollImage(String userId,String centerId){
		return dao.activityScollImage(userId,centerId);
	}
	
	public HashMap<String,Object> selectActState(String userId,String activityId){
		return dao.selectActState(userId, activityId);
	}
}
